#include<iostream>
#include<cstring>
using namespace std;

int n, sum = 0;
bool a[14], b[28], c[28];
int ans[14];

void dfs(int x){
    if(x > n) {
        sum++;
        if(sum > 3) return;
        else {
            for(int i=1; i<=n; i++) cout << ans[i] << " ";
            cout << endl;
            return ;
        }
    }
    for(int i=1; i<=n; i++) {
        if(!a[i] && !b[i+x] && !c[i-x+n]) {
            ans[x] = i;
            a[i] = b[i+x] = c[i-x+n] = true;
            dfs(x+1);
            a[i] = b[i+x] = c[i-x+n] = false;
        }
    }
}
int main(){
    memset(a, false, sizeof(a));
    memset(b, false, sizeof(b));
    memset(c, false, sizeof(c));
    memset(ans, 0, sizeof(ans));
    cin >> n;
    dfs(1);
    cout << sum << endl;
    return 0;
}